package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.Fix;
import com.home.service.FixService;

@Controller
public class FixAction {
	@Autowired
	private FixService fixService;

	public FixService getFixService() {
		return fixService;
	}

	public void setFixService(FixService fixService) {
		this.fixService = fixService;
	}

	@RequestMapping("/admin/fix/list.do")
	public String getAll(HttpServletRequest request) {
		List<Fix> fixList = this.getFixService().getList();
		request.setAttribute("list", fixList);
		return "/admin/fix/list";
	}

	@RequestMapping("/admin/fix/save.do")
	public String getAll(Fix fix) {
		if (fix != null) {
			this.getFixService().save(fix);
		}
		Cache.getInstance().refreshFix();
		return "redirect:/admin/fix/list.do";
	}

	@RequestMapping("/admin/fix/get.do")
	public String getAll(Integer id, HttpServletRequest request) {
		if (id != null) {
			Fix fix = this.getFixService().getFix(id);
			request.setAttribute("obj", fix);
		}
		return "/admin/fix/obj";
	}
	
	
	@RequestMapping("/admin/fix/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			Fix f=new Fix();
			f.setId(id);
			this.getFixService().delete(f);
		}
		return "redirect:/admin/fix/list.do";
	}

}
